package com.dfbz.demo01;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01_Map集合的常用方法 {
    public static void main(String[] args) {
        Map<String,String> map=new HashMap<>();

        map.put("河南","郑州");
        map.put("河北","石家庄");
        map.put("山东","济南");
        map.put("山西","太原");

        System.out.println(map);        // {山东=济南, 山西=太原, 河南=郑州, 河北=石家庄}
        map.remove("河北");
        System.out.println(map);        // {山东=济南, 山西=太原, 河南=郑州}

        String city = map.get("山东");
        System.out.println(city);       // 济南

        System.out.println(map.containsKey("陕西"));      // false
        System.out.println(map.containsKey("山西"));      // true
        System.out.println("------------");

        Collection<String> values = map.values();
        for (String value : values) {
            System.out.println(value);
        }
        System.out.println("--------------");

        Set<String> keys = map.keySet();
        for (String key : keys) {
            System.out.println(key);
        }
    }
}
